package com.accp.wxmp.handler;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage.Item;
import me.chanjar.weixin.mp.bean.result.WxMpUser;

/**
 * 转发客户消息Handler
 *
 * Created by FirenzesEagle on 2016/7/27 0027.
 * Email:liumingbo2008@gmail.com
 */
@Component
public class HelpHandler extends AbstractHandler {
    @Autowired
    protected WxMpService wxMpService;
    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, WxSessionManager sessionManager) throws WxErrorException {
    	WxMpUser wxMpUser = this.wxMpService.userInfo(wxMessage.getFromUserName(), "zh_CN");

//    	WxMpXmlOutTextMessage m
//        = WxMpXmlOutMessage.TEXT()
//        .content("尊敬的" + wxMpUser.getNickname() + "，您好！")
//        .fromUser(wxMessage.getToUser())
//        .toUser(wxMessage.getFromUser())
//        .build();
    	Item item1 = new Item();
    	item1.setTitle("汇鑫帮助");
    	item1.setDescription("我是描述");
		item1.setPicUrl("http://47.95.222.72:8080/static/img/bj.jpg");
		item1.setUrl("http://47.95.222.72:8080/ftl/test");
    	WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS().
		addArticle(item1).
		fromUser(wxMessage.getToUserName()).
		toUser(wxMessage.getFromUserName()).
		build();
    	
    return m;
    }
}
